package com.noodles.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.noodles.mall.entity.MenuRole;
import com.noodles.mall.entity.Role;
import com.noodles.mall.mapper.MenuRoleMapper;
import com.noodles.mall.service.MenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.noodles.mall.service.RoleService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/** 权限-角色 **/
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    /** 查找列表: menu_id **/
    public List<Role> selectList(Integer menuId){
        ArrayList<Role> list=new ArrayList<>();
        super.list(new QueryWrapper<MenuRole>().lambda()
                .eq(MenuRole::getMenuId,menuId)
        ).forEach(menuRole -> {
            list.add(RoleService.INTEGER_ROLE_MAP.get(menuRole.getRoleId()));
        });
        return list;
    }
}
